package com.gaoxin.api.contronller.statisController;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.statisentity.StudentInfo;
import com.gaoxin.api.service.statisservice.StatisExamFailCourseService;
import com.google.common.collect.Maps;

@RestController
@RequestMapping("/app/statistics")
public class StatisExamFailCourseController {
	@Autowired
	private StatisExamFailCourseService statisExamFailCourseService;
	/**
	 * 查询学生考试不及格科目
	 * @param stuNumber
	 * @param semester
	 * @return
	 */
	@RequestMapping(value="/queryFailedStu",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryFailedStuCourse(@RequestBody Map<String,String> paramMap){
		String jsonData = null;
		try {
			String stuNumber = paramMap.get("stuNumber");
			String semester = paramMap.get("semester");
			StudentInfo student =  statisExamFailCourseService.queryStudent(stuNumber);
			if(student==null){
				Map<String, Object> map = Maps.newLinkedHashMap();
				map.put("code","100505");
				map.put("errmsg","无该学生信息，请确认学生学号!");
				jsonData = JSON.toJSONString(map);
				return jsonData;
			}
			StudentInfo studentInfo = statisExamFailCourseService.queryFailedStuCourse(stuNumber, semester);
			Map<String, Object> map = Maps.newLinkedHashMap();
			if(studentInfo!=null){
				map.put("code","0");
				map.put("results",studentInfo);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code","100506");
				map.put("errmsg","该学生无不及格科目信息!");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}
